<?php

namespace app\admin\controller\user;

use app\admin\service\log\OperateLogService;
use app\admin\service\user\UserService;
use app\common\constant\OperateLogFieldMap;
use app\common\controller\CommonBaseController;
use app\common\utils\ApiReturn;
use app\Request;
use Error;
use Exception;

class User extends CommonBaseController
{
    public function insertMockData(Request $request)
    {
        try {
            //这里为了方便操作,直接在controller层执行.如果是真实业务场景下批量插入数据,建议使用command命令行执行
            $result = UserService::insertMockData();
            ApiReturn::retSuccess($result);
        } catch (Exception|Error $e) {
            ApiReturn::retError($e);
        }
    }

    public function getUserList(Request $request)
    {
        try {
            $is_export = !empty($this->params['export']);
            $list = UserService::getUserList($this->params, $is_export);
            ApiReturn::retSuccess($list);
        } catch (Exception|Error $e) {
            ApiReturn::retError($e);
        }
    }

    public function updateUserData(Request $request)
    {
        try {
            UserService::updateUserData($this->params);
            ApiReturn::retSuccess();
        } catch (Exception|Error $e) {
            ApiReturn::retError($e);
        }
    }

    public function getUserOperateLog(Request $request)
    {
        try {
            $list = OperateLogService::getList(OperateLogFieldMap::CATEGORY_USER, $this->params['id']);
            ApiReturn::retSuccess($list);
        } catch (Exception|Error $e) {
            ApiReturn::retError($e);
        }
    }
}